//
//  manpower_Controller.m
//  pmmSS
//
//  Created by Mac book on 2017/9/25.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "manpower_Controller.h"
#import "category_collection_cell.h"
#import "HomeSectionHeaderView.h"
@interface manpower_Controller()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong) UITableView *leftTableView;

@property (nonatomic,strong) UICollectionView *rightCollectionView;
@property (strong,nonatomic) UICollectionViewFlowLayout *layout;

@property (nonatomic,strong) NSArray *headerDataArray;

@property (nonatomic,strong) UILabel *headerLabel;




@end
static NSString *HeaderID = @"UICollectionReusableView";
static NSString *FooterID = @"UICollectionReusableView";
@implementation manpower_Controller

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = View_BackgroundColor;
    _headerDataArray = @[@"热门分类",@"其它"];

    [self createLeftTableView];

    [self createRightCollectionView];
    // Do any additional setup after loading the view.
}
-(void)createLeftTableView{

    _leftTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, autoScaleW(95), GET_FRAME_HEIGHT(self.view)  - 108) style:UITableViewStylePlain];

    _leftTableView.backgroundColor = [UIColor whiteColor];
    _leftTableView.rowHeight = autoScaleH(50);

    _leftTableView.delegate = self ;
    _leftTableView.dataSource = self;

    [self.view addSubview:_leftTableView];

    [_leftTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];


}
-(void)createRightCollectionView{

    self.layout = [[UICollectionViewFlowLayout alloc] init];
    self.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //确定item的大小
    self.layout.itemSize = CGSizeMake(autoScaleW(SCREEN_WIDTH - self.leftTableView.frame.size.width)/3, autoScaleH(115));

    //确定横向间距
    self.layout.minimumLineSpacing = 0;

    //确定纵向间距
    self.layout.minimumInteritemSpacing = 0;

    //确定距离上左下右的距离
    self.layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.layout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH - self.leftTableView.frame.size.width, 30);//头视图的大小


    self.layout.footerReferenceSize = CGSizeMake(SCREEN_WIDTH - self.leftTableView.frame.size.width, 50);
    self.rightCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(self.leftTableView.frame.size.width + 10, 0,autoScaleW(SCREEN_WIDTH - self.leftTableView.frame.size.width),self.leftTableView.frame.size.height) collectionViewLayout:self.layout];
    self.rightCollectionView.backgroundColor = [UIColor whiteColor];


    //禁止滑动
    //self.rightCollectionView.scrollEnabled = NO;

    self.rightCollectionView.delegate = self;
    self.rightCollectionView.dataSource = self;

    self.rightCollectionView.showsVerticalScrollIndicator = NO;

    [self.view addSubview:self.rightCollectionView];


    [self.rightCollectionView registerClass:[category_collection_cell class] forCellWithReuseIdentifier:@"category_collection_cell"];

    [self.rightCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderID];

//    [self.rightCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:FooterID];


}
#pragma mark : UITableViewDelegate,UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{


    return 10;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{



        static NSString *identifier = @"UITableViewCell";

        UITableViewCell *leftCell = [_leftTableView dequeueReusableCellWithIdentifier:identifier];
        leftCell.selectionStyle  = UITableViewCellSelectionStyleNone;

    if (indexPath.section == 0) {

       leftCell.textLabel.text = @"推荐分类";

    }else{

       leftCell.textLabel.text = @"土建";

    }

        leftCell.textLabel.textAlignment = NSTextAlignmentCenter;
        leftCell.textLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:autoScaleW(12)];
        leftCell.backgroundColor = [UIColor whiteColor];

        return leftCell;

}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {


        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        cell.textLabel.textColor = [UIColor blackColor];
        cell.backgroundColor = [UIColor whiteColor];


}
// 点击cell--本次选择的cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        cell.textLabel.textColor = [UIColor redColor];
        cell.backgroundColor = View_BackgroundColor;


}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{


    return section == 0?0:1;

}
#pragma mark : UICollectionViewDelegate,UICollectionViewDataSource

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 2;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 7;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    category_collection_cell *detailCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"category_collection_cell" forIndexPath:indexPath];

    detailCell.backgroundColor = [UIColor whiteColor];

    return detailCell;
//    return [[UICollectionViewCell alloc] init];
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{


//    [self.delegate clickCollectionItem:[NSString stringWithFormat:@"%@", _shopIdstr]];
}
//-（CGSize）collectionView:（UICollectionView *）collectionView:（UICollectionViewLayout *）collectionViewLayout referenceSizeForHeaderInSection:（NSInteger）section {
//
//    return CGSizeMake（self.frame.size.width，45）;
//}
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{



        UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderID forIndexPath:indexPath];
        headerView.backgroundColor = View_BackgroundColor;

    for (UIView *view in headerView.subviews) {
        [view removeFromSuperview];
    }

    _headerLabel = [HMLabel createLabelWithText:self.headerDataArray[indexPath.section] andTextColor:[UIColor blackColor]andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(14)] andTextAlignment:NSTextAlignmentLeft];

    [headerView addSubview:_headerLabel];


    [_headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(headerView);
        make.left.mas_equalTo(autoScaleW(20));
        make.width.mas_equalTo(autoScaleW(200));
        make.height.mas_equalTo(autoScaleH(10));

    }];

        return headerView;


}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
